// 二叉树的前序遍历
const bt = require("../tree/bt.js");

const df = (root) => {
  const res = [];
  const stack = [];
  if (root) {
    stack.push(root);
  }
  while (stack.length > 0) {
    const n = stack.pop();
    console.log(n.value);
    res.push(n.value);
    if (n.right) {
      stack.push(n.right);
    }
    if (n.left) {
      stack.push(n.left);
    }
  }
  return res;
};

console.log(df(bt));
